{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np  # 矩阵操作\n",
    "import pandas as pd # SQL数据处理\n",
    "\n",
    "from sklearn.metrics import r2_score  #评价回归预测模型的性能\n",
    "\n",
    "import matplotlib.pyplot as plt   #画图\n",
    "import seaborn as sns\n",
    "\n",
    "# 图形出现在Notebook里而不是新窗口\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>9</th>\n",
       "      <th>...</th>\n",
       "      <th>334</th>\n",
       "      <th>335</th>\n",
       "      <th>336</th>\n",
       "      <th>337</th>\n",
       "      <th>338</th>\n",
       "      <th>339</th>\n",
       "      <th>340</th>\n",
       "      <th>341</th>\n",
       "      <th>342</th>\n",
       "      <th>SalePrice</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.227483</td>\n",
       "      <td>-0.202770</td>\n",
       "      <td>0.064327</td>\n",
       "      <td>-0.243378</td>\n",
       "      <td>0.700717</td>\n",
       "      <td>0.026216</td>\n",
       "      <td>0.226042</td>\n",
       "      <td>1.253123</td>\n",
       "      <td>-0.419233</td>\n",
       "      <td>1.053769</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>208500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.670403</td>\n",
       "      <td>-0.086107</td>\n",
       "      <td>0.064327</td>\n",
       "      <td>-0.243378</td>\n",
       "      <td>0.700717</td>\n",
       "      <td>0.026216</td>\n",
       "      <td>0.226042</td>\n",
       "      <td>-0.694099</td>\n",
       "      <td>1.858393</td>\n",
       "      <td>0.159469</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>181500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.316067</td>\n",
       "      <td>0.081281</td>\n",
       "      <td>0.064327</td>\n",
       "      <td>-0.243378</td>\n",
       "      <td>-1.028509</td>\n",
       "      <td>0.026216</td>\n",
       "      <td>0.226042</td>\n",
       "      <td>1.253123</td>\n",
       "      <td>-0.419233</td>\n",
       "      <td>0.987524</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>223500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.079843</td>\n",
       "      <td>-0.091179</td>\n",
       "      <td>0.064327</td>\n",
       "      <td>-0.243378</td>\n",
       "      <td>-1.028509</td>\n",
       "      <td>0.026216</td>\n",
       "      <td>0.226042</td>\n",
       "      <td>1.253123</td>\n",
       "      <td>-0.419233</td>\n",
       "      <td>-1.860986</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>140000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.788515</td>\n",
       "      <td>0.386636</td>\n",
       "      <td>0.064327</td>\n",
       "      <td>-0.243378</td>\n",
       "      <td>-1.028509</td>\n",
       "      <td>0.026216</td>\n",
       "      <td>0.226042</td>\n",
       "      <td>1.253123</td>\n",
       "      <td>-0.419233</td>\n",
       "      <td>0.954402</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>250000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 344 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1         2         3         4         5         6  \\\n",
       "0  0.227483 -0.202770  0.064327 -0.243378  0.700717  0.026216  0.226042   \n",
       "1  0.670403 -0.086107  0.064327 -0.243378  0.700717  0.026216  0.226042   \n",
       "2  0.316067  0.081281  0.064327 -0.243378 -1.028509  0.026216  0.226042   \n",
       "3  0.079843 -0.091179  0.064327 -0.243378 -1.028509  0.026216  0.226042   \n",
       "4  0.788515  0.386636  0.064327 -0.243378 -1.028509  0.026216  0.226042   \n",
       "\n",
       "          7         8         9    ...      334  335  336  337  338  339  340  \\\n",
       "0  1.253123 -0.419233  1.053769    ...        1    1    1    1    1    1    1   \n",
       "1 -0.694099  1.858393  0.159469    ...        1    1    1    1    1    1    1   \n",
       "2  1.253123 -0.419233  0.987524    ...        1    1    1    1    1    1    1   \n",
       "3  1.253123 -0.419233 -1.860986    ...        1    1    1    1    1    1    1   \n",
       "4  1.253123 -0.419233  0.954402    ...        1    1    1    1    1    1    1   \n",
       "\n",
       "   341  342  SalePrice  \n",
       "0    1    1     208500  \n",
       "1    1    1     181500  \n",
       "2    1    1     223500  \n",
       "3    1    1     140000  \n",
       "4    1    1     250000  \n",
       "\n",
       "[5 rows x 344 columns]"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dpath = './week1_job_data/Ames_House/'\n",
    "train_data = pd.read_csv(dpath +\"AmesHouse_FE_train.csv\")\n",
    "# train_data = train_data.\n",
    "train_data = train_data[train_data.SalePrice < 400000]\n",
    "test_data = pd.read_csv(dpath +\"AmesHouse_FE_test.csv\")\n",
    "#通过观察前5行，了解数据每列（特征）的概况\n",
    "train_data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 从原始数据中分离输入特征x和输出y\n",
    "y = train_data['SalePrice'].values\n",
    "X = train_data.drop('SalePrice', axis = 1)\n",
    "#将数据分割训练数据与测试数据\n",
    "from sklearn.cross_validation import train_test_split\n",
    "\n",
    "# 随机采样25%的数据构建测试样本，其余作为训练样本\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=20, test_size=0.2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_data = test_data.drop('Id',axis = 1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 数据标准化\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "\n",
    "# 分别初始化对特征和目标值的标准化器\n",
    "ss_X = StandardScaler()\n",
    "ss_y = StandardScaler()\n",
    "\n",
    "# 分别对训练和测试数据的特征以及目标值进行标准化处理\n",
    "X_train = ss_X.fit_transform(X_train)\n",
    "X_test = ss_X.transform(X_test)\n",
    "\n",
    "#y_train = ss_y.fit_transform(y_train)\n",
    "#y_test = ss_y.transform(y_test)\n",
    "\n",
    "y_train = ss_y.fit_transform(y_train.reshape(-1, 1))\n",
    "y_test = ss_y.transform(y_test.reshape(-1, 1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "lr1.intercept_ -110278305701.0\n",
      "lr1.coef_ [  1.07170019e+03   5.99133161e+03   1.41988030e+03  -4.21566598e+02\n",
      "  -1.67115493e+02   8.49233512e+02   9.88313238e+02   4.76695236e+10\n",
      "  -3.76711271e+03   1.44001051e+04   1.96498857e+03   2.52442036e+03\n",
      "  -2.83115266e+09  -1.15726913e+03  -1.35615047e+02   2.32903790e+02\n",
      "   3.02896724e+03   1.07648896e+03  -3.68533816e+13   5.17257386e+02\n",
      "  -1.38351560e+13  -3.78762815e+13   1.24397282e+14   1.37388292e+03\n",
      "   8.34891142e+13   9.75555161e+13   2.78587443e+13  -1.76872313e+14\n",
      "   1.61185655e+14   3.70372309e+13   1.70613066e+14   7.82739771e+13\n",
      "  -2.38310699e+03  -7.61644101e+03  -8.52574676e+03   2.36484087e+03\n",
      "   3.96845214e+03   1.57130892e+10   5.30291176e+02  -1.15412057e+03\n",
      "  -1.96771414e+10  -4.24348994e+05  -2.56805860e+03  -2.32240344e+03\n",
      "  -1.33291826e+01   2.43090432e+03  -4.74317883e+14  -4.44123959e+14\n",
      "  -2.13069013e+14  -4.05194011e+14   1.25896171e+03  -5.09510596e+03\n",
      "   3.94507499e+03   3.79774344e+02   1.19911910e+04   2.42519444e+03\n",
      "   3.88848778e+02   1.06702550e+04  -1.57130873e+10   3.55766751e+03\n",
      "   5.37294368e+03  -2.42405006e+14  -1.64399086e+14   1.70329838e+14\n",
      "   7.61055801e+14   7.11319878e+10   3.68589217e+09   1.09582531e+05\n",
      "  -4.82649684e+04   7.33437806e+04   5.07219320e+05  -1.51991576e+05\n",
      "   3.48244180e+05  -4.23716393e+05   1.24795485e+05  -3.41217347e+05\n",
      "  -4.35416653e+10   1.75228588e+10  -2.16963064e+10   9.97221543e+09\n",
      "  -2.67025233e+09   1.57514909e+10   3.74048078e+04  -1.63713667e+04\n",
      "  -6.10195097e+02   2.79466393e+05  -9.56974654e+04   2.95362030e+05\n",
      "   1.65569322e+05  -4.20233025e+04   1.63349055e+05   1.24685463e+10\n",
      "  -1.34231930e+10   3.78579910e+09   6.19794960e+05  -2.29736678e+05\n",
      "   4.11033366e+05   2.78442256e+10   2.78442352e+10   4.30461128e+10\n",
      "   2.78442197e+10   2.78442240e+10  -1.41437236e+10  -2.86093852e+10\n",
      "  -2.86093797e+10   2.52519345e+09   3.08773489e+09   3.08773324e+09\n",
      "   3.08774272e+09   3.08773902e+09   3.08774008e+09   3.08772259e+09\n",
      "   3.08773580e+09   3.08770902e+09   3.08775060e+09   4.13011219e+09\n",
      "   4.86368391e+09   4.86368889e+09   4.86368880e+09   4.86375146e+09\n",
      "   4.86371743e+09   4.86367797e+09   4.86369032e+09   4.86368898e+09\n",
      "   2.77417266e+10   1.96952402e+09   1.96952118e+09   1.96953234e+09\n",
      "   1.96953470e+09   1.96952220e+09   2.16415015e+09   2.44527222e+09\n",
      "   2.44526271e+09   2.44525151e+09   2.44528090e+09   8.11021374e+09\n",
      "   2.44518842e+09   2.44526364e+09   3.12912959e+09   2.44526684e+09\n",
      "   2.44526616e+09   2.44527445e+09   2.44526640e+09   2.44526114e+09\n",
      "   2.44525820e+09   2.44526619e+09  -1.55418038e+10   3.90329261e+09\n",
      "   3.90330305e+09   3.90330754e+09   3.90329726e+09  -1.76167019e+09\n",
      "   3.90337960e+09   3.90329725e+09   3.90330467e+09   3.90330367e+09\n",
      "   1.59246643e+09   3.90329246e+09   3.90330639e+09   3.90331426e+09\n",
      "   3.90330428e+09   3.90330717e+09   3.90329824e+09   8.28517723e+09\n",
      "  -7.94291524e+09  -7.94290972e+09  -7.94291144e+09  -7.94291692e+09\n",
      "  -7.94291102e+09   6.81335002e+09   9.31722332e+09   9.31722307e+09\n",
      "   9.31722807e+09   9.31722314e+09   9.31722018e+09   9.31717643e+09\n",
      "   3.83065563e+09  -8.33519409e+08   7.95327780e+09  -8.33526014e+08\n",
      "  -8.33524633e+08  -7.06617218e+09  -1.40514065e+09  -1.40510699e+09\n",
      "  -1.40510003e+09  -1.40510659e+09  -1.40510832e+09  -1.40510639e+09\n",
      "   7.95024858e+09   6.01679032e+09   2.81303564e+08   2.81321138e+08\n",
      "   2.81316193e+08   2.81316396e+08   2.81308972e+08   2.81327654e+08\n",
      "  -1.55263572e+10  -2.24780072e+08  -2.24768137e+08  -2.24770072e+08\n",
      "  -2.24753194e+08  -2.24747953e+08  -2.24768194e+08  -2.24772710e+08\n",
      "  -2.24756269e+08   1.58185064e+09  -4.83524345e+09  -4.83524422e+09\n",
      "  -4.83524750e+09  -4.83524852e+09   3.04984579e+08   3.33158336e+10\n",
      "   3.33158384e+10   3.33158275e+10   3.33158109e+10   3.33158315e+10\n",
      "   1.17992165e+09   4.44038169e+09   1.16931051e+09   4.44036741e+09\n",
      "   4.44037484e+09   4.44037752e+09   4.44039064e+09   4.44038579e+09\n",
      "   4.44038814e+09   4.44038802e+09   4.44040541e+09   4.44038962e+09\n",
      "   4.44039689e+09   4.44037421e+09   4.44037805e+09   4.44038781e+09\n",
      "  -1.07615106e+10   6.90766800e+08  -2.06578313e+10  -2.06577673e+10\n",
      "  -2.06577853e+10  -2.06577862e+10  -2.06577950e+10  -4.39069063e+08\n",
      "  -2.55822176e+10  -2.55822124e+10   1.19508398e+11  -2.55822046e+10\n",
      "   6.94222002e+09  -7.16833666e+09  -7.16822398e+09  -7.16821885e+09\n",
      "  -7.16822525e+09  -7.16830190e+09  -1.27054388e+09   5.78592678e+09\n",
      "   5.78592687e+09   5.78592837e+09   5.78592217e+09   5.78592582e+09\n",
      "   5.78592605e+09   5.78592522e+09   5.78592660e+09   5.78592664e+09\n",
      "   5.78592422e+09   5.78592563e+09   5.78592947e+09   0.00000000e+00\n",
      "   6.31335697e+09   6.31338265e+09   6.31338315e+09   6.31337397e+09\n",
      "   6.31335403e+09   6.31335574e+09   6.31337818e+09   6.31335022e+09\n",
      "   6.31335380e+09   6.31336809e+09   6.31335297e+09   6.31335273e+09\n",
      "   6.31335424e+09   6.31337791e+09   6.31335919e+09   6.31336942e+09\n",
      "   6.31338610e+09   6.31336064e+09   6.31335749e+09   6.31336083e+09\n",
      "   6.31335882e+09   6.31335840e+09   6.31339824e+09   6.31336232e+09\n",
      "   6.31338108e+09   0.00000000e+00  -1.11037003e+09   0.00000000e+00\n",
      "  -1.11037208e+09  -1.11036998e+09  -1.11038727e+09  -1.11036271e+09\n",
      "  -1.11033853e+09   0.00000000e+00   1.30213767e+10   1.30213538e+10\n",
      "   1.30213548e+10   1.30213566e+10   1.30213616e+10   1.30214035e+10\n",
      "   0.00000000e+00   5.48845070e+09   5.48847193e+09   5.48846209e+09\n",
      "   5.48845476e+09   5.48846062e+09  -7.76523455e+09   0.00000000e+00\n",
      "  -1.14511728e+08  -1.14472455e+08  -1.14481181e+08  -1.14495159e+08\n",
      "  -1.14512721e+08  -1.14510165e+08  -1.14485871e+08  -1.14521672e+08\n",
      "  -1.14510734e+08   0.00000000e+00   0.00000000e+00   0.00000000e+00\n",
      "   0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00\n",
      "   0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00\n",
      "   0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00\n",
      "   0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00\n",
      "   0.00000000e+00   0.00000000e+00   0.00000000e+00]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([  1.07170019e+03,   5.99133161e+03,   1.41988030e+03,\n",
       "        -4.21566598e+02,  -1.67115493e+02,   8.49233512e+02,\n",
       "         9.88313238e+02,   4.76695236e+10,  -3.76711271e+03,\n",
       "         1.44001051e+04,   1.96498857e+03,   2.52442036e+03,\n",
       "        -2.83115266e+09,  -1.15726913e+03,  -1.35615047e+02,\n",
       "         2.32903790e+02,   3.02896724e+03,   1.07648896e+03,\n",
       "        -3.68533816e+13,   5.17257386e+02,  -1.38351560e+13,\n",
       "        -3.78762815e+13,   1.24397282e+14,   1.37388292e+03,\n",
       "         8.34891142e+13,   9.75555161e+13,   2.78587443e+13,\n",
       "        -1.76872313e+14,   1.61185655e+14,   3.70372309e+13,\n",
       "         1.70613066e+14,   7.82739771e+13,  -2.38310699e+03,\n",
       "        -7.61644101e+03,  -8.52574676e+03,   2.36484087e+03,\n",
       "         3.96845214e+03,   1.57130892e+10,   5.30291176e+02,\n",
       "        -1.15412057e+03,  -1.96771414e+10,  -4.24348994e+05,\n",
       "        -2.56805860e+03,  -2.32240344e+03,  -1.33291826e+01,\n",
       "         2.43090432e+03,  -4.74317883e+14,  -4.44123959e+14,\n",
       "        -2.13069013e+14,  -4.05194011e+14,   1.25896171e+03,\n",
       "        -5.09510596e+03,   3.94507499e+03,   3.79774344e+02,\n",
       "         1.19911910e+04,   2.42519444e+03,   3.88848778e+02,\n",
       "         1.06702550e+04,  -1.57130873e+10,   3.55766751e+03,\n",
       "         5.37294368e+03,  -2.42405006e+14,  -1.64399086e+14,\n",
       "         1.70329838e+14,   7.61055801e+14,   7.11319878e+10,\n",
       "         3.68589217e+09,   1.09582531e+05,  -4.82649684e+04,\n",
       "         7.33437806e+04,   5.07219320e+05,  -1.51991576e+05,\n",
       "         3.48244180e+05,  -4.23716393e+05,   1.24795485e+05,\n",
       "        -3.41217347e+05,  -4.35416653e+10,   1.75228588e+10,\n",
       "        -2.16963064e+10,   9.97221543e+09,  -2.67025233e+09,\n",
       "         1.57514909e+10,   3.74048078e+04,  -1.63713667e+04,\n",
       "        -6.10195097e+02,   2.79466393e+05,  -9.56974654e+04,\n",
       "         2.95362030e+05,   1.65569322e+05,  -4.20233025e+04,\n",
       "         1.63349055e+05,   1.24685463e+10,  -1.34231930e+10,\n",
       "         3.78579910e+09,   6.19794960e+05,  -2.29736678e+05,\n",
       "         4.11033366e+05,   2.78442256e+10,   2.78442352e+10,\n",
       "         4.30461128e+10,   2.78442197e+10,   2.78442240e+10,\n",
       "        -1.41437236e+10,  -2.86093852e+10,  -2.86093797e+10,\n",
       "         2.52519345e+09,   3.08773489e+09,   3.08773324e+09,\n",
       "         3.08774272e+09,   3.08773902e+09,   3.08774008e+09,\n",
       "         3.08772259e+09,   3.08773580e+09,   3.08770902e+09,\n",
       "         3.08775060e+09,   4.13011219e+09,   4.86368391e+09,\n",
       "         4.86368889e+09,   4.86368880e+09,   4.86375146e+09,\n",
       "         4.86371743e+09,   4.86367797e+09,   4.86369032e+09,\n",
       "         4.86368898e+09,   2.77417266e+10,   1.96952402e+09,\n",
       "         1.96952118e+09,   1.96953234e+09,   1.96953470e+09,\n",
       "         1.96952220e+09,   2.16415015e+09,   2.44527222e+09,\n",
       "         2.44526271e+09,   2.44525151e+09,   2.44528090e+09,\n",
       "         8.11021374e+09,   2.44518842e+09,   2.44526364e+09,\n",
       "         3.12912959e+09,   2.44526684e+09,   2.44526616e+09,\n",
       "         2.44527445e+09,   2.44526640e+09,   2.44526114e+09,\n",
       "         2.44525820e+09,   2.44526619e+09,  -1.55418038e+10,\n",
       "         3.90329261e+09,   3.90330305e+09,   3.90330754e+09,\n",
       "         3.90329726e+09,  -1.76167019e+09,   3.90337960e+09,\n",
       "         3.90329725e+09,   3.90330467e+09,   3.90330367e+09,\n",
       "         1.59246643e+09,   3.90329246e+09,   3.90330639e+09,\n",
       "         3.90331426e+09,   3.90330428e+09,   3.90330717e+09,\n",
       "         3.90329824e+09,   8.28517723e+09,  -7.94291524e+09,\n",
       "        -7.94290972e+09,  -7.94291144e+09,  -7.94291692e+09,\n",
       "        -7.94291102e+09,   6.81335002e+09,   9.31722332e+09,\n",
       "         9.31722307e+09,   9.31722807e+09,   9.31722314e+09,\n",
       "         9.31722018e+09,   9.31717643e+09,   3.83065563e+09,\n",
       "        -8.33519409e+08,   7.95327780e+09,  -8.33526014e+08,\n",
       "        -8.33524633e+08,  -7.06617218e+09,  -1.40514065e+09,\n",
       "        -1.40510699e+09,  -1.40510003e+09,  -1.40510659e+09,\n",
       "        -1.40510832e+09,  -1.40510639e+09,   7.95024858e+09,\n",
       "         6.01679032e+09,   2.81303564e+08,   2.81321138e+08,\n",
       "         2.81316193e+08,   2.81316396e+08,   2.81308972e+08,\n",
       "         2.81327654e+08,  -1.55263572e+10,  -2.24780072e+08,\n",
       "        -2.24768137e+08,  -2.24770072e+08,  -2.24753194e+08,\n",
       "        -2.24747953e+08,  -2.24768194e+08,  -2.24772710e+08,\n",
       "        -2.24756269e+08,   1.58185064e+09,  -4.83524345e+09,\n",
       "        -4.83524422e+09,  -4.83524750e+09,  -4.83524852e+09,\n",
       "         3.04984579e+08,   3.33158336e+10,   3.33158384e+10,\n",
       "         3.33158275e+10,   3.33158109e+10,   3.33158315e+10,\n",
       "         1.17992165e+09,   4.44038169e+09,   1.16931051e+09,\n",
       "         4.44036741e+09,   4.44037484e+09,   4.44037752e+09,\n",
       "         4.44039064e+09,   4.44038579e+09,   4.44038814e+09,\n",
       "         4.44038802e+09,   4.44040541e+09,   4.44038962e+09,\n",
       "         4.44039689e+09,   4.44037421e+09,   4.44037805e+09,\n",
       "         4.44038781e+09,  -1.07615106e+10,   6.90766800e+08,\n",
       "        -2.06578313e+10,  -2.06577673e+10,  -2.06577853e+10,\n",
       "        -2.06577862e+10,  -2.06577950e+10,  -4.39069063e+08,\n",
       "        -2.55822176e+10,  -2.55822124e+10,   1.19508398e+11,\n",
       "        -2.55822046e+10,   6.94222002e+09,  -7.16833666e+09,\n",
       "        -7.16822398e+09,  -7.16821885e+09,  -7.16822525e+09,\n",
       "        -7.16830190e+09,  -1.27054388e+09,   5.78592678e+09,\n",
       "         5.78592687e+09,   5.78592837e+09,   5.78592217e+09,\n",
       "         5.78592582e+09,   5.78592605e+09,   5.78592522e+09,\n",
       "         5.78592660e+09,   5.78592664e+09,   5.78592422e+09,\n",
       "         5.78592563e+09,   5.78592947e+09,   0.00000000e+00,\n",
       "         6.31335697e+09,   6.31338265e+09,   6.31338315e+09,\n",
       "         6.31337397e+09,   6.31335403e+09,   6.31335574e+09,\n",
       "         6.31337818e+09,   6.31335022e+09,   6.31335380e+09,\n",
       "         6.31336809e+09,   6.31335297e+09,   6.31335273e+09,\n",
       "         6.31335424e+09,   6.31337791e+09,   6.31335919e+09,\n",
       "         6.31336942e+09,   6.31338610e+09,   6.31336064e+09,\n",
       "         6.31335749e+09,   6.31336083e+09,   6.31335882e+09,\n",
       "         6.31335840e+09,   6.31339824e+09,   6.31336232e+09,\n",
       "         6.31338108e+09,   0.00000000e+00,  -1.11037003e+09,\n",
       "         0.00000000e+00,  -1.11037208e+09,  -1.11036998e+09,\n",
       "        -1.11038727e+09,  -1.11036271e+09,  -1.11033853e+09,\n",
       "         0.00000000e+00,   1.30213767e+10,   1.30213538e+10,\n",
       "         1.30213548e+10,   1.30213566e+10,   1.30213616e+10,\n",
       "         1.30214035e+10,   0.00000000e+00,   5.48845070e+09,\n",
       "         5.48847193e+09,   5.48846209e+09,   5.48845476e+09,\n",
       "         5.48846062e+09,  -7.76523455e+09,   0.00000000e+00,\n",
       "        -1.14511728e+08,  -1.14472455e+08,  -1.14481181e+08,\n",
       "        -1.14495159e+08,  -1.14512721e+08,  -1.14510165e+08,\n",
       "        -1.14485871e+08,  -1.14521672e+08,  -1.14510734e+08,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n",
       "         0.00000000e+00])"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.linear_model import LinearRegression\n",
    "\n",
    "# 使用默认配置初始化\n",
    "lr = LinearRegression()\n",
    "\n",
    "# 训练模型参数\n",
    "lr.fit(X_train, y_train)\n",
    "\n",
    "# 预测，下面计算score会自动调用predict\n",
    "lr_y_predict = lr.predict(X_test)\n",
    "lr_y_predict_train = lr.predict(X_train)\n",
    "\n",
    "# 预测，下面计算score会自动调用predict\n",
    "lr_y_predict = lr.predict(X_test)\n",
    "predict_value_lr = lr.predict(test_data)\n",
    "\n",
    "#显示特征的回归系数\n",
    "print 'lr1.intercept_',lr.intercept_\n",
    "print 'lr1.coef_',lr.coef_\n",
    "lr.coef_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The value of default measurement of LinearRegression on test is -5874478.85047\n",
      "The value of default measurement of LinearRegression on train is 0.942914394796\n"
     ]
    }
   ],
   "source": [
    "#测试集\n",
    "print 'The value of default measurement of LinearRegression on test is', lr.score(X_test, y_test)\n",
    "\n",
    "#训练集\n",
    "print 'The value of default measurement of LinearRegression on train is', lr.score(X_train, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "MSE: 2.47491813729e+16\n",
      "RMSE: 157318725.436\n"
     ]
    }
   ],
   "source": [
    "from sklearn import metrics\n",
    "# 用scikit-learn计算MSE\n",
    "print \"MSE:\",metrics.mean_squared_error(y_test, lr_y_predict)\n",
    "# 用scikit-learn计算RMSE\n",
    "print \"RMSE:\",np.sqrt(metrics.mean_squared_error(y_test, lr_y_predict))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count":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zF3PvH3VY137IzN/D/yC10PyeOANwH3UAvpaagPPAPYF7qze0xuAT2bmo92s\n9kxqp+X/BFwKfL/L66dU21sB7Ab8e91rf0vttP4zwE+pfRDoSbf7eP0tlgZHZHZ31k/SQKh6u09T\nOyXeXXBJ0jrseUsDLCI+UJ0C3pjaHcx+Dywe3FpJKonhLQ282dQGij0O7ETt9KynwCT1mqfNJUkq\njD1vSZIKM9j/9ACArbfeOqdMmTLY1ZAkaVDNnz//ycycsKH5hkR4T5kyhXnz5g12NSRJGlQR0as7\nCHraXJKkwhjekiQVxvCWJKkwQ+KatySpZ6+++ipLlizhpZe8W+twMW7cOCZPnsyYMWP6tbzhLUlD\n3JIlS9hkk02YMmUKEc36h3IaLJnJihUrWLJkCVOnTu3XOjxtLklD3EsvvcRWW21lcA8TEcFWW23V\n0JkUw1uSCmBwDy+N7k/DW5KkwnjNW5IK094+8OsbNWoUe+yxB6tWrWLq1Kn88Ic/ZPPNN+/ztj72\nsY/xmc98hl133XWt8ksvvZR58+Zx4YUX9nmdAOPHj2flypW9mnfmzJmcf/75tLW1rSmbN28el112\nGRdccEG/tj/Q7HlLkjbojW98IwsWLOCee+5hyy235KKLLurXev75n/95neAeCtra2loe3KtXr27a\nujYY3hFxSUQ8ERH31JXNjYgF1WNxRCyoyqdExIt1r32naTWVJA0JM2bMYOnSpWuen3feeey7777s\nueeenHPOOQA8//zzHHbYYey1117svvvuzJ07F6j1ejtvh/3973+fnXfemfe85z3cfvvta9Z34okn\ncu211655Pn78eABWrlzJrFmz2Hvvvdljjz24/vrr16nbsmXLOPDAA5k2bRq77747v/zlL3vVpltv\nvZXDDz8cgPb2dk466SRmzpzJDjvssFaoX3755ey3335MmzaN0047bU0gn3766bS1tbHbbruteQ+g\ndvvvc889l3e/+91cc801vapLb/TmtPmlwIXAZZ0FmXlU53REfAN4pm7+hzNzWrMqKEkaOlavXs3N\nN9/MySefDMCNN97IQw89xF133UVmcsQRR3DbbbfR0dHBtttuy09/+lMAnnnmmbXWs2zZMs455xzm\nz5/PZpttxnvf+16mT5++3m2PGzeO6667jk033ZQnn3yS/fffnyOOOGKtwV8/+tGPOPjggzn77LNZ\nvXo1L7zwQr/a+cADD3DLLbfw3HPPscsuu3D66aezaNEi5s6dy+23386YMWM444wzuOKKKzj++OP5\n2te+xpZbbsnq1auZNWsWCxcuZM8991xT71/96lf9qkdPNhjemXlbREzp7rWovWMfAf6sqbWSJA0p\nL774ItOmTWPx4sXss88+vO997wNq4X3jjTeuCd6VK1fy0EMPccABB/DZz36Wz3/+8xx++OEccMAB\na63vzjvvZObMmUyYUPsHWkcddRR/+MMf1luHzOSLX/wit912GxtttBFLly5l+fLlvPnNb14zz777\n7stJJ53Eq6++ypFHHsm0af3rSx522GGMHTuWsWPHMnHiRJYvX87NN9/M/Pnz2Xfffde8JxMnTgTg\n6quvZs6cOaxatYply5Zx3333rQnvo446qsft9Fej17wPAJZn5kN1ZVMj4rcR8YuIOKCnBSVJ5ei8\n5v3YY4/xyiuvrLnmnZmcddZZLFiwgAULFrBo0SJOPvlkdt55Z+bPn88ee+zBWWedxbnnnrvOOnv6\nutTo0aN57bXX1qz/lVdeAeCKK66go6OD+fPns2DBArbZZpt1vit94IEHctttt7Hddttx3HHHcdll\nl62z/t4YO3bsmulRo0axatUqMpMTTjhhTVsffPBB2tvbefTRRzn//PO5+eabWbhwIYcddtha9dp4\n4437VYf1aXS0+THAlXXPlwFvycwVEbEP8JOI2C0zn+26YEScCpwK8Ja3vKXBakjS6/oyGrvZI7eH\nu80224wLLriA2bNnc/rpp3PwwQfzpS99iWOPPZbx48ezdOlSxowZw6pVq9hyyy356Ec/yvjx47n0\n0kvXWs873/lOPvnJT7JixQo23XRTrrnmGvbaay+gdp14/vz5fOQjH+H666/n1VdfBWqn3idOnMiY\nMWO45ZZbeOyxdf975mOPPcZ2223HKaecwvPPP8/dd9/N8ccf35S2z5o1i9mzZ/PpT3+aiRMn8tRT\nT/Hcc8/x7LPPsvHGG7PZZpuxfPlyfv7znzN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wjbt\nUB1Xv6uOsbP7e/xQOwW9qHrUh2a3x2iL2/UmYAWwWV3ZkNlP3h5VkqTCDNXR5pIkqQeGtyRJhTG8\nJUkqjOEtSVJhDG9JkgpjeEuSVBjDW5Kkwvx/miQBMzwk59oAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x153feef0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#在训练集上观察预测残差的分布，看是否符合模型假设：噪声为0均值的高斯噪声\n",
    "f, ax = plt.subplots(figsize=(7, 5)) \n",
    "f.tight_layout() \n",
    "ax.hist(y_train - lr_y_predict_train,bins=40, label='Residuals Linear', color='b', alpha=.5); \n",
    "ax.set_title(\"Histogram of Residuals\") \n",
    "ax.legend(loc='best');"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAARkAAADQCAYAAAAzgBXfAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJztnX+UXFWV7z/fdCrQQaETiE7oAIlO\nJhjkR6SFOHkzIyzll/yIjGIQnwzjyFNxjQgTSZ4uAw6zjOKow5sZlTf4gxEhQTD8EMwggeU8lvzo\n2IkxQiSgQhqWhJV0wKQhnfR+f9xTSXV13Vu3u+veut29P2vdVbf2PfeeXUnV7nP22XsfmRmO4zhZ\nMaHZCjiOM7ZxI+M4Tqa4kXEcJ1PcyDiOkyluZBzHyRQ3Mo7jZIobGcdxMsWNjOM4mZK5kZHUIqlL\n0j3h/SxJj0p6StIKSZOC/IDwfnO4PrPiGUuDfJOk0yvkZwTZZklLKuQ1+3AcJ3+UdcSvpCuADuBg\nMztb0krgDjO7VdI3gfVm9g1J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0/bnZIT7ZJyGE5yx2yXNljQBeG/F\n5Z8SZQUDIOmEmMecJqlN0mTgPODhOt3+FFhUniZVTJfS9udkhBsZJyuuIprePMDAanaXAQuCg/bX\nwEdj7v9/RPVru4BbzGxdUmdJ7MO4AAAAUklEQVRm9kuiOr8/C1Xurhtif05G+BK2Uzgk/R3wVjO7\nvNm6OCPHRzKO42SKj2Qcx8kUH8k4jpMpbmQcx8kUNzKO42SKGxnHcTLFjYzjOJny/wF/cvHzOrn8\nPQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x14e7f278>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#还可以观察预测值与真值的散点图\n",
    "plt.figure(figsize=(4, 3))\n",
    "plt.scatter(y_train, lr_y_predict_train)\n",
    "plt.plot([-3, 3], [-3, 3], '--k')   #数据已经标准化，3倍标准差即可\n",
    "plt.axis('tight')\n",
    "plt.xlabel('True price')\n",
    "plt.ylabel('Predicted price')\n",
    "plt.tight_layout()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 113609.42059326  151455.06648254  191764.22869873 ...,  168434.24032593\n",
      "  129606.36816406  232397.49777222]\n"
     ]
    }
   ],
   "source": [
    "# predict_value_lr = lr.predict(test_data)\n",
    "# final_predict_value_lasso = np.exp(predict_value_lasso)\n",
    "# final_predict_value_lr = ss_y.inverse_transform(predict_value_lr)\n",
    "print predict_value_lr\n",
    "# ss['sale_price'] = predict_value_lasso\n",
    "# ss.head()\n",
    "# pred_lasso = pd.DataFrame(predict_value_lasso, index=test_data[\"Id\"], columns=[\"SalePrice\"])\n",
    "pred_lr = pd.DataFrame(predict_value_lr, columns=[\"SalePrice\"])\n",
    "pred_lr.to_csv('Lr_Predicting_house_price_output.csv', header=True, index_label='Id')\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
